[#import "/framework/JGP.htm"  as JGP]
<!--
项目   jgp-cloud-parent
作者   LOUFEI [Gavin]
时间   2019-11-03
-->
[@JGP.head "系统管理员"/]
[@JGP.body]
    <jgp-div _row="['30','80','*']" _runit="px" _aux="true">
        <div slot="1-1">
            <jgp-btn _fn="createSystemAdmin">创建</jgp-btn>
            <jgp-btn _color="caution" _fn="deleteInBatch">批量删除</jgp-btn>
        </div>
        <jgp-query slot="2-1" _id="query-form" _target="grid" _action="/security/user-api-ctl/query-system-admin">
            <jgp-form-group _title="查询条件">
                <jgp-text _col="4" _name="realName" _placeholder="请输入真实姓名"></jgp-text>
                <jgp-text _col="4" _name="username" _placeholder="请输入用户名"></jgp-text>
                <jgp-text _col="4" _name="tel" _placeholder="请输入手机号"></jgp-text>
                <jgp-drop _col="3" _name="locked" _label="账号状态" _list="[{'label':'','value':''},{'label':'锁定','value':true}]"></jgp-drop>
            </jgp-form-group>
        </jgp-query>
        <jgp-grid slot="3-1" _id="grid" _cols="['100','100','100','200','200']" _cunit="px"
                  _record_tools="[{'tip':'密码重置','fn':'resetPassword','icon':'key'},
                  {'tip':'锁定','fn':'lock','icon':'lock'},
                  {'tip':'解锁','fn':'unLock','icon':'unlock-alt'},
                  {'tip':'删除','fn':'deleteOne','icon':'trash-o'}]"></jgp-grid>
    </jgp-div>
[/@JGP.body]

[@JGP.foot]
    <script>
        function createSystemAdmin() {
            var dialog = {
                'title': '创建系统管理员',
                'width': '320px',
                'height': '270px',
                'url': '/security/user-ctl/edit-system-admin'
            };
            JGP.$dialog(dialog);
        }

        function resetPassword(args) {
            JGP.$confirm("是否确定重置密码？",function () {
                JGP.$post("/security/user-api-ctl/reset-password",{
                    userId:args.back.record.id
                },function (result) {
                    if(result.flag){
                        JGP.$alert("重置成功!新密码("+result.data.pwd+")");
                    }
                })
            });

        }

        function deleteInBatch() {
            JGP.$confirm("是否确定删除？",function () {
                var selected = JGP.grid('grid').getSelected();
                var ids = [];
                for(var i=0;i<selected.length;i++){
                    ids.push(selected[i].id);
                }
                JGP.$postJson("/security/user-api-ctl/remove-system-admin",ids,function (result) {
                    if(result.flag){
                        JGP.$alert("删除成功");
                        JGP.query('query-form').search();
                    }
                })
            });
        }

        function deleteOne(args) {
            JGP.$confirm("是否确定删除？", function () {
                var ids = [args.back.record.id];

                JGP.$postJson("/security/user-api-ctl/remove-system-admin", ids, function (result) {
                    if (result.flag) {
                        JGP.$alert("删除成功");
                        JGP.query('query-form').search();
                    }
                })
            });
        }

        function lock(args) {
            var username = args.back.record.username;
            JGP.$confirm('是否锁定账号('+username+')?',function () {
                var userId = args.back.record.id;
                JGP.$post('/security/user-api-ctl/lock',{userId:userId},function () {
                    JGP.$alert('('+username+')已经锁定');
                })
            })
        }

        function unLock(args) {
            var username = args.back.record.username;
            JGP.$confirm('是否解锁账号('+username+')?',function () {
                var userId = args.back.record.id;
                JGP.$post('/security/user-api-ctl/un-lock',{userId:userId},function () {
                    JGP.$alert('('+username+')已经解锁');
                })
            })
        }
    </script>
[/@JGP.foot]